#include <memory>
//继承std::enable_shared_from_this<myClass>
class myClass : public std::enable_shared_from_this<myClass>
{
public: 
    std::shared_ptr<myClass> getShared()
    {
        //返回shared_from_this()
        return shared_from_this();
    }
};

template<class T>
class enable_shared_from_this 
{
protected:
    mutable weak_ptr<T> weak_this;
public:
    shared_ptr<T> shared_from_this() 
    {
        return shared_ptr<T>(weak_this);  // 从 weak_ptr 创建 shared_ptr
    }
};


int main()
{
    auto p1 = std::make_shared<myClass>();
    auto p2 = p1->getShared();
    return 0;
}